﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectEulerSolutions
{/*
  * 
  * Starting in the top left corner of a 2×2 grid, there are 6 routes (without backtracking) to the bottom right corner.

    How many routes are there through a 20×20 grid?

  * 
  * */
    class Problem15
    {
        public static string Calculate()
        {
            long dimensions = 20;

            long adder = 1;



            long[] line = new long[dimensions];

            for (long i = 1; i < line.Length; i++)
                line[i] = 1;

            line[0] = 2;


            for (int j = 0; j < dimensions; j++)
            {
                adder = line[j];
                for (int i = j; i < dimensions; i++)
                {
                    if (j == 0)
                    {
                        if (i == 0)
                        {
                            line[i] = 1 + 1;
                        }
                        else
                        {
                            line[i] = line[i - 1] + 1;
                        }
                    }
                    else
                    {
                        line[i] += adder;
                        adder = line[i];
                    }
                }
            }


            return line[dimensions - 1].ToString();
        }
    }
}
